#define ID3LIB_LINKOPTION 1


#include <wx/textctrl.h>
#include "SongListFrame.h"
#include <wx/dir.h>
#include <wx/treectrl.h>
#include "wx/wx.h" 
#include "MainFrame.h"

enum {
	ID_TREECTRL = 1
};

SongListFrame::SongListFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame( NULL, -1, title, pos, size ) 
{
	
	sizer1 = new wxBoxSizer(wxHORIZONTAL);
	wxGridSizer* mainFrameGrid = new wxGridSizer(1, 1, 0, 0);
    SetSizer(mainFrameGrid);
	wxTreeCtrl *myTreeCtrl = new wxTreeCtrl(this, ID_TREECTRL, wxDefaultPosition, wxSize(360,760));
	mainFrameGrid->Add(sizer1,1,0,0);



	wxTreeItemId rootNode = myTreeCtrl->AddRoot(wxT("Root Item"));
	wxTreeItemId node_A = myTreeCtrl->AppendItem(rootNode, wxT("A"));
	wxTreeItemId node_B = myTreeCtrl->AppendItem(rootNode, wxT("B"));
	wxTreeItemId node_Aa= myTreeCtrl->AppendItem(node_A, wxT("Aa"));
	wxString a;
	a << myTreeCtrl->GetCount();
	wxTreeItemId node_Ab= myTreeCtrl->AppendItem(node_A,a);

}

void SongListFrame::NextDirLevel(wxString *Path, FILE *logFile){
	
	wxDir dir(*Path);
	if ( !dir.IsOpened() )
    {
        // deal with the error here - wxDir would already log an error message
        // explaining the exact reason of the failure
        return;
    }
	//wxString *myNextFile;
	wxString myNextFolder;
	wxString filespec = wxT("*.*");
	
	int flagsFiles = wxDIR_FILES;
	int flagsDir = wxDIR_DIRS;
	bool cont = dir.GetFirst(&myNextFolder, filespec, flagsDir);
	if(cont)
	{
		fprintf(logFile,Path->c_str());
		myNextFolder = *Path + wxT("\\") + myNextFolder;
		NextDirLevel(&myNextFolder, logFile);
		fprintf(logFile,myNextFolder.c_str());
		fprintf(logFile, "\n");

	}
	else fprintf(logFile, "Found end of directory.\n");
	while(cont = dir.GetNext(&myNextFolder))
	{
		myNextFolder = *Path + wxT("\\") + myNextFolder;
		NextDirLevel(&myNextFolder, logFile);
		fprintf(logFile,myNextFolder.c_str());
		fprintf(logFile, "\n");
	}
	//bool cont = dir.GetFirst(&myNextFile,filespec,flagsFiles
	//while(myNextFile = )


}

void SongListFrame::ImportMusic(wxString *FolderPath)
{


	wxDir dir(*FolderPath);

    if ( !dir.IsOpened() )
    {
        // deal with the error here - wxDir would already log an error message
        // explaining the exact reason of the failure
        return;
    }


    wxString filename;
	wxString filespec = wxT("*.*");
	int flagsFiles = wxDIR_FILES | wxDIR_DIRS;
	int flagsDir = wxDIR_DIRS;
    bool cont = dir.GetFirst(&filename, filespec, flagsDir);
	/* Creates log file for MainFrame class. */ 
	FILE * pFileSongListFrame;
	pFileSongListFrame = fopen("Logs\\SongListFrameLog.txt", "w");/* This should be checked for null. */
	fprintf(pFileSongListFrame, "Debug SongListFrame Log\n");
    NextDirLevel(FolderPath, pFileSongListFrame);

	fclose(pFileSongListFrame);/* #FIXUP Figure out where this should go. */
	/*
	wxListItem item;
    item.SetId(numElements);
    item.SetText(SongPath);//Is this neccessary?
    guiSongList->InsertItem( item );
	guiSongList->SetItem(numElements, 0, *SongName);
	guiSongList->SetItem(numElements, 1, *ArtistName);
	guiSongList->SetItem(numElements, 2, *Duration);
    sizer1->Add(guiSongList,1, wxEXPAND | wxALL, 10);


*/
}



void SongListFrame::GetNextFile(){





}